package com.ruoyi.bom.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.bom.domain.TqlMaterialTransUnit;
import com.ruoyi.bom.service.ITqlMaterialTransUnitService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物料单位转化表Controller
 * 
 * @author ruoyi
 * @date 2024-03-28
 */
@RestController
@RequestMapping("/unitTranfer")
public class TqlMaterialTransUnitController extends BaseController
{
    @Autowired
    private ITqlMaterialTransUnitService tqlMaterialTransUnitService;

    /**
     * 查询物料单位转化表列表
     */
    @RequiresPermissions("bom:unitTranfer:list")
    @GetMapping("/list")
    public TableDataInfo list(TqlMaterialTransUnit tqlMaterialTransUnit)
    {
        startPage();
        List<TqlMaterialTransUnit> list = tqlMaterialTransUnitService.selectTqlMaterialTransUnitList(tqlMaterialTransUnit);
        return getDataTable(list);
    }

    /**
     * 导出物料单位转化表列表
     */
    @RequiresPermissions("bom:unitTranfer:export")
    @Log(title = "物料单位转化表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TqlMaterialTransUnit tqlMaterialTransUnit)
    {
        List<TqlMaterialTransUnit> list = tqlMaterialTransUnitService.selectTqlMaterialTransUnitList(tqlMaterialTransUnit);
        ExcelUtil<TqlMaterialTransUnit> util = new ExcelUtil<TqlMaterialTransUnit>(TqlMaterialTransUnit.class);
        util.exportExcel(response, list, "物料单位转化表数据");
    }

    /**
     * 获取物料单位转化表详细信息
     */
    @RequiresPermissions("bom:unitTranfer:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tqlMaterialTransUnitService.selectTqlMaterialTransUnitById(id));
    }

    /**
     * 新增物料单位转化表
     */
    @RequiresPermissions("bom:unitTranfer:add")
    @Log(title = "物料单位转化表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TqlMaterialTransUnit tqlMaterialTransUnit)
    {
        return toAjax(tqlMaterialTransUnitService.insertTqlMaterialTransUnit(tqlMaterialTransUnit));
    }

    /**
     * 修改物料单位转化表
     */
    @RequiresPermissions("bom:unitTranfer:edit")
    @Log(title = "物料单位转化表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TqlMaterialTransUnit tqlMaterialTransUnit)
    {
        return toAjax(tqlMaterialTransUnitService.updateTqlMaterialTransUnit(tqlMaterialTransUnit));
    }

    /**
     * 删除物料单位转化表
     */
    @RequiresPermissions("bom:unitTranfer:remove")
    @Log(title = "物料单位转化表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tqlMaterialTransUnitService.deleteTqlMaterialTransUnitByIds(ids));
    }
}
